package com.ruoyi.APPMS.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.APPMS.domain.Purchasepartorder;
import com.ruoyi.APPMS.service.IPurchasepartorderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 零部件订单Controller
 *
 * @author 任容
 * @date 2023-07-04
 */
@Api(tags = "采购零部件订单")
@RestController
@RequestMapping("/purchasepartorder/purchasepartorder")
public class PurchasepartorderController extends BaseController {
    @Autowired
    private IPurchasepartorderService purchasepartorderService;

    /**
     * 查询零部件订单列表
     */
    @ApiOperation("分页查询零部件订单列表")
    @PreAuthorize("@ss.hasPermi('purchasepartorder:purchasepartorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(Purchasepartorder purchasepartorder) {
        startPage();
//        QueryWrapper<Purchasepartorder> queryWrapper=new QueryWrapper<>();
        List<Purchasepartorder> list = purchasepartorderService.list(purchasepartorder);
        return getDataTable(list);
    }

    /**
     * 导出零部件订单列表
     */
    @ApiOperation("导出零部件订单列表")
    @PreAuthorize("@ss.hasPermi('purchasepartorder:purchasepartorder:export')")
    @Log(title = "零部件订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Purchasepartorder purchasepartorder) {
//        QueryWrapper<Purchasepartorder> queryWrapper=new QueryWrapper<>();
        List<Purchasepartorder> list = purchasepartorderService.list(purchasepartorder);
        ExcelUtil<Purchasepartorder> util = new ExcelUtil<Purchasepartorder>(Purchasepartorder.class);
        util.exportExcel(response, list, "零部件订单数据");
    }

    /**
     * 获取零部件订单详细信息
     */
    @ApiOperation("获取零部件订单详细信息")
    @PreAuthorize("@ss.hasPermi('purchasepartorder:purchasepartorder:query')")
    @GetMapping(value = "/{purchasepartorderid}")
    public AjaxResult getInfo(@PathVariable("purchasepartorderid") Long purchasepartorderid) {
        return success(purchasepartorderService.listByID(purchasepartorderid));
    }

    /**
     * 新增零部件订单
     */
    //@ApiOperation("新增零部件订单")
    @PreAuthorize("@ss.hasPermi('purchasepartorder:purchasepartorder:add')")
    @Log(title = "零部件订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Purchasepartorder purchasepartorder) {
        purchasepartorder.setCreatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return toAjax(purchasepartorderService.save(purchasepartorder));
    }

    /**
     * 发货-零部件订单
     */
    @ApiOperation("发货-零部件订单")
    @PreAuthorize("@ss.hasPermi('purchasepartorder:purchasepartorder:edit')")
    @Log(title = "零部件订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Purchasepartorder purchasepartorder) {
        purchasepartorder.setModifytime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        System.out.println(purchasepartorder);
        purchasepartorderService.createLogistic1(purchasepartorder);
        purchasepartorderService.createLogistic3(purchasepartorder);
        return toAjax(purchasepartorderService.createLogistic2(purchasepartorder));
    }

    /**
     * 删除零部件订单
     */
    //@ApiOperation("删除零部件订单")
    @PreAuthorize("@ss.hasPermi('purchasepartorder:purchasepartorder:remove')")
    @Log(title = "零部件订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{purchasepartorderids}")
    public AjaxResult remove(@PathVariable List<Long> purchasepartorderids) {
        return toAjax(purchasepartorderService.removeByIds(purchasepartorderids));
    }
}
